package cm.util6.theme3;

/**
 * 单词单词序列
 * https://www.nowcoder.com/practice/3194a4f4cf814f63919d0790578d51f3
 */
public class ReverseSentenceDemo {
    public String ReverseSentence(String str) {
        if (str==null||str.isEmpty()){
            return "";
        }

        String[] words = str.split(" ");
        StringBuilder result = new StringBuilder();
        result.append(words[words.length-1]);
        for (int i = words.length - 2; i >= 0; i--) {
            result.append(" ").append(words[i]);
        }
        return result.toString();
    }

    /**
     * 一个单词的翻转
     * @param word
     * @return
     */
    public String reverseWord(String word) {
        return new StringBuilder(word).reverse().toString();
    }
}
